function [data, outHist] = fromCellData( imCell, Params_pre, pathCell, inHist)
%fromCellData  prevede bunkove pole obrazku imCell na matici realnych cisel
%              imCell obsahuje vstupni obrazky
%              Params_pre - parametry
%              pathCell - bunkove pole s cestami k vstupnim obrazkum
%              inHist - histogram podle ktereho se maji fotky normalizovat
%                       (volitelne)
%              vysledkem je matice m x n, kde
%                   m je dimense jednoho vzorku
%                   n je pocet vzorku

columns = size(imCell,2);

velips = zeros(5, columns); %elipsy

addpath('./elipse');

% hledani elipsy
if Params_pre.elipse
    for i=1:columns
        [imCell{i}, ve] = simplePreprocess(imCell{i}, pathCell{i}, Params_pre.elipseCache, Params_pre.CIR, Params_pre.center, Params_pre.rotate);
        velips(:,i) = ve';
    end
end

% vyvazeni svetla
if Params_pre.lightBalance
    for i=1:columns
        imCell{i} = lightBalance(imCell{i});
    end
end

% ekvalizace histogramu
if Params_pre.eqhist 
    if nargin < 4
        %vypocet prumerneho histogramu
        bins = 128;
        inHist = zeros(bins+1,1);
        for i = 1:columns            
            iv = reshape(imCell{i}, numel(imCell{i}), 1);
            inHist = inHist + histc(iv, linspace(0,1,bins+1));
        end
        inHist(bins) = inHist(bins) + inHist(bins+1);
        inHist = inHist(1:bins);
        inHist = round(smooth(inHist, 15, 'moving'));
    end
    outHist = inHist;
    
    for i=1:columns
        imCell{i} = histeq(imCell{i},inHist);
    end
else
    outHist = NaN;
end
    
features = str2func(Params_pre.img2vecFnc); %funkce pro prevod obrazku na vektor
% extrakce ficur
for i=1:columns
    if Params_pre.elipse
        imv = features(imCell{i}, Params_pre.img2vecFncArgs,velips(:,i)');
    else
        imv = features(imCell{i},Params_pre.img2vecFncArgs);
    end    
    if i == 1
        rows = length(imv);
        data = zeros(rows,columns);
    end;            
    data(:,i) = imv;
end;